package org.bing.zion.helper;

import java.nio.ByteBuffer;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class DirectBufferPool {
	protected final Queue<ByteBuffer> buffers = new ConcurrentLinkedQueue<ByteBuffer>();
	private static final DirectBufferPool instance = new DirectBufferPool();

	// TODO impl dynamic cache, ex SoftRefrence etc
	private DirectBufferPool() {

	}

	public static DirectBufferPool instance() {
		return instance;
	}

	// TODO trace buffer lifecycle
	public ByteBuffer obtain() {
		// ByteBuffer buf = buffers.poll();
		// if (buf == null) {
		// buf = ByteBuffer.allocateDirect(4096);
		//
		// }
		ByteBuffer buf = ByteBuffer.allocate(4096);
		return buf;
	}

	public void release(ByteBuffer buf) {
		// buf.clear();
		// buffers.offer(buf);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
